package com.tsxy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tsxy.entity.Area;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AreaMapper extends BaseMapper<Area> {


    @Select("select id,pid,name,level,merger_name  from area where level = 1")
    @Results({
            @Result(column = "id" ,property = "id"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "name",property = "name"),
            @Result(column = "merger_name" ,property = "mergerName"),
            @Result(column = "level",property = "level"),
            @Result(column = "id" ,property = "child",
                 many = @Many(select = "selectByPid"))
    })
    List<Area> getAllChildren();

    @Select("select id,pid,name,level,merger_name from area where pid = #{pid}")
    List<Area> selectByPid(Integer pid);

}
